package com.asp.utils;

import com.alibaba.dashscope.aigc.conversation.Conversation;
import com.alibaba.dashscope.aigc.conversation.ConversationParam;
import com.alibaba.dashscope.utils.Constants;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * author:          ndg
 * date:            2024/1/10
 */
@Data
@AllArgsConstructor
@Slf4j
public class AliTyUtils {
    private String apiKey;

    public String start(String prompt) {
        Constants.apiKey = apiKey;
        Conversation conversation = new Conversation();
        ConversationParam param = ConversationParam
                .builder()
                .model(Conversation.Models.QWEN_TURBO)
                .prompt(prompt)
                .build();
        String answer = null;
        try {
            answer = conversation.call(param).getOutput().getText();
            conversation.call(param);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return answer;
    }
}
